using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class JobSeekers_educations : System.Web.UI.Page
{
    string connectionString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        connectionString =
             WebConfigurationManager.ConnectionStrings[
               "RecruitVietnam"].ConnectionString;
        if (Session.Contents["jsuserid"] == null)
        {
                Response.Redirect("login.aspx");
        }
        else        
        {
            if(!IsPostBack)
            {
                ShowEducation();
            }
        }
    }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        Response.Redirect("experiences.aspx");
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        DeleteEducation();
        ShowEducation();
    }
    void ShowEducation()
    {
        SqlServerProvider cls = new 
        SqlServerProvider(connectionString);
        cls.CommandText = "SPViewEducations";
        cls.CommandType = 
        CommandType.StoredProcedure;
        cls.ParameterCollection = 
        new string[1] {"@UserID"};
        cls.ValueCollection = new 
        string[1]{Convert.ToString(
        Session.Contents["jsuserid"])};

        DataTable dataTable = cls.GetDataTable();
        GridViewHelper helper 
        = new GridViewHelper();
        helper.FillDataTableToGridView(
        dataTable, GridView1);
        if(dataTable.Rows.Count == 0) 
            btnDelete.Visible = false;
    }
    void DeleteEducation()
    {
        string educationID="";
        foreach(GridViewRow item in GridView1.Rows)
        {
            CheckBox checkBox = (CheckBox)
            item.Cells[0].FindControl("chkEducationID");
            if(checkBox.Checked)
                educationID+= item.Cells[0].Text +",";
        }
        if(educationID!="")
        {
            SqlServerProvider cls = new 
            SqlServerProvider(connectionString);
            cls.CommandText = 
            "delete  from tblJSEducations" +
            " where UserID=@UserID " +
            " and educationID in('" + 
            educationID.Replace(",","','")+ "')";
            cls.ParameterCollection = 
            new string[1] { "@UserID" };
            cls.ValueCollection = 
            new string[1]{Convert.ToString(
            Session.Contents["jsuserid"])};
            cls.ExecuteNonQuery( );
        }
    }
    protected void btnNew_Click(object sender, EventArgs e)
    {
        Response.Redirect("education.aspx");
    }
}
